package com.dao.impl;

import com.dao.InstitutyDao;
import com.entry.Instituty;
import com.util.DBHelper;

import java.util.ArrayList;

public class InstitutyDaoImpl implements InstitutyDao {

    private DBHelper db = new DBHelper();

    @Override
    public ArrayList<Instituty> selectQuery(Instituty instituty) {
        StringBuilder sql = new StringBuilder("select * from systerm2 where 1=1");
        if (instituty.getInstituty_id() != null) {
            sql.append("and instituty_id like?");
            return db.selectinfo(sql.toString(), Instituty.class, "%" + instituty.getInstituty_id() + "%");
        } else if (instituty.getName() != null) {
            sql.append("and name like?");
            return db.selectinfo(sql.toString(), Instituty.class, "%" + instituty.getName() + "%");
        } else if (instituty.getInterest() != null) {
            sql.append("and interest like?");
            return db.selectinfo(sql.toString(), Instituty.class, "%" + instituty.getInterest() + "%");
        } else if (instituty.getReceipt_day() != null) {
            sql.append("and receipt_day like?");
            return db.selectinfo(sql.toString(), Instituty.class, "%" + instituty.getReceipt_day() + "%");
        }else {
            return  db.selectinfo(sql.toString(),Instituty.class);
        }
    }

    @Override
    public Instituty selectByInstituty_id(int Instituty_id) {
        String sql = "select * from where instituty_id";
        return (Instituty) (db.selectinfo(sql, Instituty.class, Instituty_id)).get(0);
    }
}
